<template>
	<view class="main">
			<u-navbar :is-back="true" title="商家红包" :background="background" back-icon-color="#000000" title-color="#000" title-bold="true"></u-navbar>
			<view class="lists">
				<view class="content" v-for="(item,index) in giftlist" :key="index">
					<text>{{item.price}}元红包</text>
					<image src="../../../static/images/remove.png"  @click="showmodle(item.id)"></image>
				</view>
			
			</view>
	<view class="confirm" @click="router">
		添加红包
	</view>
	<u-modal v-model="show" show-cancel-button="true"  :content="content" @confirm="confirm"></u-modal>
	</view>
</template>
<script>


	export default {
		data() {
			return {
				background: {
					backgroundColor:'#fff'
				},
			giftlist:'',
				content: '此操作将会删除该活动',
				show:false,
				index:''
				
			}
		},
		onLoad() {
			
			
			
			var that =this
			uni.showLoading({
				title: '加载中',
			});
			setTimeout(function () {
				uni.hideLoading();
				that.getgift()
			}, 700);
				
		},
		mounted() {
		
		},
		onShow() {},
		methods: {
			showmodle(e){
				this.show=true,
				this.index=e
				
			},
			router(){
				uni.navigateTo({
					url:'../add_gift/add_gift'
				})
			},
			//确认删除红包
			confirm(){
				console.log(222);
				console.log(this.index);
				global.$http.request({
					url:'/shopapi/activity/envelopesdel',
					data:{
						token:uni.getStorageSync('token'),
						id:this.index
					}
				}).then(res=>{
					var that =this
					if(res.data.code==200){
						uni.showToast({
							title:res.data.msg,
							icon:'none',
							duration:1000
						})
					uni.showLoading({
						title: '加载中',
					});
					setTimeout(function () {
						uni.hideLoading();
						that.getgift()
					}, 1000);
					}else{
						uni.showToast({
							title:res.data.msg,
							icon:'none',
							duration:1000
						})
					}
				})
			},
			//获取红包列表
			getgift(){
				global.$http.request({
					url:'/shopapi/activity/envelopeslist',
					data:{
						token:uni.getStorageSync('token')
					}
				}).then(res=>{
					console.log(res.data.data);
					if(res.data.code==200){
						this.giftlist=res.data.data
					}
				})
			}
		}
	}
</script>
<style lang="scss">
	page {
		font-family: PingFang SC;
		width: 750rpx;
		margin: 0 auto;
		
		background-color: #f7f7f7;
		.main {
			width: 750rpx;
			margin: 0 auto;
			.lists{
				margin: 10rpx 0 150rpx 0;
				.content{
					padding: 30rpx;
					background-color: #fff;
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 28rpx;
					font-weight: 400;
					color: #FF0000;
					margin-bottom: 2rpx;
					image{
						width: 18rpx;
						height: 18rpx;
					}
					
				}
				
			}
			.confirm{
				position: fixed;
				bottom: 0;
				width: 750rpx;
				text-align: center;
				padding: 34rpx 0;
				background: #FE4E00;
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;
				
			}
		}
	}
</style>
